"""样式管理模块
统一管理应用程序的所有样式定义
"""

import platform


class StyleManager:
    """样式管理器"""
    
    def __init__(self):
        # 根据操作系统选择字体
        system = platform.system()
        if system == "Windows":
            self.font_family = "'Microsoft YaHei', 'SimHei', sans-serif"
        elif system == "Darwin":  # macOS
            self.font_family = "'PingFang SC', 'Helvetica Neue', sans-serif"
        else:  # Linux
            self.font_family = "'Noto Sans CJK SC', 'DejaVu Sans', sans-serif"
        
        # 字体大小配置
        self.scale_factor = 1.0  # 可以根据需要调整
        self.base_font_size = max(9, int(10 * self.scale_factor))
        self.button_font_size = max(8, int(9 * self.scale_factor))
    
    def get_main_stylesheet(self):
        """获取主样式表"""
        return f"""
            /* 主窗口 - IDEA深色主题 */
            QMainWindow {{
                background-color: #2B2B2B;
                color: #A9B7C6;
                font-family: {self.font_family};
                font-size: {self.base_font_size}pt;
            }}
            
            /* 工具栏 - IDEA风格 */
            QToolBar {{
                background-color: #3C3F41;
                border: none;
                border-bottom: 1px solid #555555;
                padding: 4px 8px;
                spacing: 4px;
                min-height: 32px;
            }}
            
            /* 工具按钮 - IDEA风格 */
            QToolButton {{
                background-color: transparent;
                border: 1px solid transparent;
                border-radius: 4px;
                padding: 6px 12px;
                font-size: {self.button_font_size}pt;
                color: #A9B7C6;
                min-width: 60px;
                min-height: 24px;
            }}
            
            QToolButton:hover {{
                background-color: #4C5052;
                border-color: #6B6B6B;
            }}
            
            QToolButton:pressed {{
                background-color: #2E3133;
                border-color: #4B6EAF;
            }}
            
            QToolButton::menu-indicator {{
                width: 20px;
                height: 20px;
                subcontrol-position: right center;
                subcontrol-origin: padding;
                right: 4px;
            }}
            
            QToolButton[popupMode="1"]::menu-indicator {{
                width: 20px;
                height: 20px;
                subcontrol-position: right center;
                subcontrol-origin: padding;
                right: 4px;
            }}
            
            /* 按钮样式 - IDEA蓝色主题 */
            QPushButton {{
                background-color: #4A88C7;
                color: #FFFFFF;
                border: 1px solid #4A88C7;
                border-radius: 4px;
                padding: 8px 16px;
                font-size: {self.button_font_size}pt;
                font-weight: normal;
                min-width: 80px;
                min-height: 28px;
            }}
            
            QPushButton:hover {{
                background-color: #5394D1;
                border-color: #5394D1;
            }}
            
            QPushButton:pressed {{
                background-color: #3A7BC0;
                border-color: #3A7BC0;
            }}
            
            QPushButton:disabled {{
                background-color: #4C5052;
                color: #6B6B6B;
                border-color: #4C5052;
            }}
            
            /* 标签样式 */
            QLabel {{
                color: #A9B7C6;
                font-size: {self.base_font_size}pt;
                background-color: transparent;
            }}
            
            /* 文本编辑器 - IDEA编辑器风格 */
            QTextEdit {{
                background-color: #2B2B2B;
                color: #A9B7C6;
                border: 1px solid #555555;
                border-radius: 4px;
                padding: 8px;
                font-size: {self.base_font_size}pt;
                font-family: {self.font_family};
                selection-background-color: #214283;
                selection-color: #FFFFFF;
            }}
            
            QTextEdit:focus {{
                border-color: #4A88C7;
            }}
            
            /* 滚动条 - IDEA风格 */
            QScrollBar:vertical {{
                background-color: #3C3F41;
                width: 12px;
                border: none;
                border-radius: 6px;
            }}
            
            QScrollBar::handle:vertical {{
                background-color: #6B6B6B;
                border-radius: 6px;
                min-height: 20px;
                margin: 0px;
            }}
            
            QScrollBar::handle:vertical:hover {{
                background-color: #7C7C7C;
            }}
            
            QScrollBar::add-line:vertical, QScrollBar::sub-line:vertical {{
                height: 0px;
            }}
            
            QScrollBar:horizontal {{
                background-color: #3C3F41;
                height: 12px;
                border: none;
                border-radius: 6px;
            }}
            
            QScrollBar::handle:horizontal {{
                background-color: #6B6B6B;
                border-radius: 6px;
                min-width: 20px;
                margin: 0px;
            }}
            
            QScrollBar::handle:horizontal:hover {{
                background-color: #7C7C7C;
            }}
            
            QScrollBar::add-line:horizontal, QScrollBar::sub-line:horizontal {{
                width: 0px;
            }}
            
            /* 下拉框 - IDEA风格 */
            QComboBox {{
                background-color: #45494A;
                color: #A9B7C6;
                border: 1px solid #6B6B6B;
                border-radius: 4px;
                padding: 6px 8px;
                font-size: {self.base_font_size}pt;
                min-width: 100px;
                min-height: 24px;
            }}
            
            QComboBox:hover {{
                border-color: #4A88C7;
            }}
            
            QComboBox:focus {{
                border-color: #4A88C7;
            }}
            
            QComboBox::drop-down {{
                subcontrol-origin: padding;
                subcontrol-position: top right;
                width: 20px;
                border-left: 1px solid #6B6B6B;
                border-top-right-radius: 4px;
                border-bottom-right-radius: 4px;
                background-color: #45494A;
            }}
            
            QComboBox::down-arrow {{
                image: none;
                border-left: 4px solid transparent;
                border-right: 4px solid transparent;
                border-top: 4px solid #A9B7C6;
                width: 0;
                height: 0;
            }}
            
            QComboBox QAbstractItemView {{
                background-color: #3C3F41;
                color: #A9B7C6;
                border: 1px solid #6B6B6B;
                selection-background-color: #4A88C7;
                selection-color: #FFFFFF;
            }}
            
            /* 进度条 - IDEA风格 */
            QProgressBar {{
                background-color: #45494A;
                border: 1px solid #6B6B6B;
                border-radius: 4px;
                text-align: center;
                color: #A9B7C6;
                font-size: {max(8, int(9 * self.scale_factor))}pt;
                min-height: 20px;
            }}
            
            QProgressBar::chunk {{
                background-color: #4A88C7;
                border-radius: 3px;
            }}
            
            /* 消息框 - IDEA风格 */
            QMessageBox {{
                background-color: #3C3F41;
                color: #A9B7C6;
                font-size: {self.base_font_size}pt;
            }}
            
            QMessageBox QPushButton {{
                min-width: 70px;
                padding: 6px 12px;
                font-size: {self.base_font_size}pt;
            }}
            
            /* 菜单 - IDEA风格 */
            QMenu {{
                background-color: #3C3F41;
                color: #A9B7C6;
                border: 1px solid #6B6B6B;
                padding: 4px 0px;
            }}
            
            QMenu::item {{
                padding: 6px 20px;
                background-color: transparent;
            }}
            
            QMenu::item:selected {{
                background-color: #4A88C7;
                color: #FFFFFF;
            }}
            
            QMenu::separator {{
                height: 1px;
                background-color: #6B6B6B;
                margin: 4px 0px;
            }}
        """
    
    def get_left_widget_style(self):
        """获取左侧组件样式"""
        return """
            QWidget {
                background-color: #2B2B2B;
                border: 1px solid #555555;
                border-radius: 6px;
            }
        """
    
    def get_date_label_style(self):
        """获取日期标签样式"""
        return """
            font-size: 13px; 
            color: #808080; 
            margin-bottom: 20px;
            font-weight: normal;
        """
    
    def get_description_label_style(self):
        """获取描述标签样式"""
        return """
            font-size: 14px; 
            color: #A9B7C6; 
            line-height: 1.5;
            padding: 16px;
            background-color: #3C3F41;
            border-radius: 6px;
            border: 1px solid #555555;
            font-weight: normal;
        """
    
    def get_title_label_style(self):
        """获取标题标签样式"""
        return """
            font-size: 32px; 
            font-weight: bold; 
            color: #4A88C7;
            margin-bottom: 15px;
            padding: 16px;
            background-color: rgba(74, 136, 199, 0.1);
            border-radius: 8px;
            border: 2px solid #4A88C7;
        """
    
    def get_version_label_style(self):
        """获取版本标签样式"""
        return """
            font-size: 16px; 
            color: #A9B7C6; 
            margin-bottom: 8px;
            font-weight: normal;
        """
    
    def get_author_label_style(self):
        """获取作者标签样式"""
        return """
            font-size: 14px; 
            color: #808080; 
            margin-bottom: 25px;
            font-style: italic;
        """
    
    def get_features_title_style(self):
        """获取功能标题样式"""
        return """
            font-size: 18px; 
            font-weight: bold; 
            color: #A9B7C6; 
            margin-bottom: 18px;
            padding: 12px;
            background-color: #3C3F41;
            border-radius: 6px;
            border: 1px solid #555555;
        """
    
    def get_features_text_style(self):
        """获取功能文本样式"""
        return f"""
            QTextEdit {{
                background-color: #2B2B2B;
                border: 1px solid #555555;
                border-radius: 6px;
                padding: 16px;
                font-size: 13px;
                color: #A9B7C6;
                line-height: 1.5;
                font-family: {self.font_family};
            }}
        """
    
    def get_instruction_label_style(self):
        """获取说明标签样式"""
        return """
            font-size: 14px; 
            color: #A9B7C6; 
            margin-top: 20px; 
            font-style: italic;
            font-weight: normal;
            padding: 12px;
            background-color: #3C3F41;
            border-radius: 6px;
            border: 1px solid #555555;
        """
    
    def get_path_label_style(self):
        """获取路径标签样式"""
        return f"""
            background-color: #45494A;
            padding: 10px 14px;
            border: 1px solid #6B6B6B;
            border-radius: 4px;
            font-size: 13px;
            color: #A9B7C6;
            font-weight: normal;
            font-family: {self.font_family};
        """
    
    def get_interface_title_style(self):
        """获取界面标题样式"""
        return """
            font-size: 18px; 
            font-weight: bold; 
            color: #A9B7C6;
            padding: 15px;
            background-color: #3C3F41;
            border-radius: 6px;
            border-left: 3px solid #4A88C7;
            border-top: 1px solid #555555;
            border-right: 1px solid #555555;
            border-bottom: 1px solid #555555;
        """
    
    def get_file_list_title_style(self):
        """获取文件列表标题样式"""
        return """
            font-size: 14px;
            font-weight: bold;
            color: #A9B7C6;
            padding: 5px;
            background-color: #3C3F41;
            border-radius: 6px;
            border-bottom: 1px solid #555555;
            margin-bottom: 10px;
        """
    
    def get_file_list_style(self):
        """获取文件列表样式"""
        return """
            QTextEdit {
                background-color: #1E1E1E;
                border: 1px solid #444444;
                border-radius: 4px;
                color: #CCCCCC;
                font-size: 12px;
                padding: 8px;
            }
        """
    
    def get_tab_widget_style(self):
        """获取标签页组件样式"""
        return """
            QTabWidget::pane {
                border: 1px solid #555555;
                background-color: #2B2B2B;
                border-radius: 6px;
            }
            QTabBar::tab {
                background-color: #3C3F41;
                color: #A9B7C6;
                padding: 8px 16px;
                margin-right: 2px;
                border-top-left-radius: 4px;
                border-top-right-radius: 4px;
                border: 1px solid #555555;
                border-bottom: none;
            }
            QTabBar::tab:selected {
                background-color: #2B2B2B;
                color: #FFFFFF;
                border-bottom: 1px solid #2B2B2B;
            }
            QTabBar::tab:hover {
                background-color: #4A88C7;
            }
        """
    
    def get_folder_button_style(self):
        """获取文件夹按钮样式"""
        return """
            QPushButton {
                background-color: #5A9FD4;
                color: #FFFFFF;
                border: 1px solid #5A9FD4;
                border-radius: 4px;
                padding: 10px 20px;
                font-size: 14px;
                font-weight: bold;
                min-width: 120px;
                min-height: 36px;
            }
            
            QPushButton:hover {
                background-color: #6BAEE0;
                border-color: #6BAEE0;
            }
            
            QPushButton:pressed {
                background-color: #4A88C7;
                border-color: #4A88C7;
            }
        """
    
    def get_folder_path_label_style(self):
        """获取文件夹路径标签样式"""
        return f"""
            color: #A9B7C6;
            font-size: 12px;
            padding: 8px;
            background-color: #2B2B2B;
            border: 1px solid #555555;
            border-radius: 4px;
            font-family: {self.font_family};
        """
    
    def get_batch_convert_button_style(self):
        """获取批量转换按钮样式"""
        return """
            QPushButton {
                background-color: #6A9955;
                color: #FFFFFF;
                border: 1px solid #6A9955;
                border-radius: 4px;
                padding: 12px 24px;
                font-size: 16px;
                font-weight: bold;
                min-width: 140px;
                min-height: 40px;
            }
            
            QPushButton:hover {
                background-color: #7BA05F;
                border-color: #7BA05F;
            }
            
            QPushButton:pressed {
                background-color: #5A8A45;
                border-color: #5A8A45;
            }
            
            QPushButton:disabled {
                background-color: #4C5052;
                color: #6B6B6B;
                border-color: #4C5052;
            }
        """
    
    def get_result_text_style(self):
        """获取结果文本样式"""
        return f"""
            QTextEdit {{
                background-color: #2B2B2B;
                border: 1px solid #555555;
                border-radius: 4px;
                padding: 12px;
                font-size: 12px;
                color: #A9B7C6;
                font-family: {self.font_family};
                min-height: 120px;
                max-height: 200px;
            }}
        """
    
    def get_format_label_style(self):
        """获取格式标签样式"""
        return "color: #A9B7C6; font-size: 14px; font-weight: bold;"
    
    def get_format_combo_style(self):
        """获取格式下拉框样式"""
        return """
            QComboBox {
                background-color: #45494A;
                color: #A9B7C6;
                border: 1px solid #6B6B6B;
                border-radius: 4px;
                padding: 8px 12px;
                font-size: 14px;
                font-weight: bold;
                min-width: 120px;
                min-height: 32px;
            }
            
            QComboBox:hover {
                border-color: #4A88C7;
                background-color: #4C5052;
            }
            
            QComboBox:focus {
                border-color: #4A88C7;
            }
            
            QComboBox::drop-down {
                subcontrol-origin: padding;
                subcontrol-position: top right;
                width: 25px;
                border-left: 1px solid #6B6B6B;
                border-top-right-radius: 4px;
                border-bottom-right-radius: 4px;
                background-color: #45494A;
            }
            
            QComboBox::down-arrow {
                image: none;
                border-left: 5px solid transparent;
                border-right: 5px solid transparent;
                border-top: 5px solid #A9B7C6;
                width: 0;
                height: 0;
            }
            
            QComboBox QAbstractItemView {
                background-color: #3C3F41;
                color: #A9B7C6;
                border: 1px solid #6B6B6B;
                selection-background-color: #4A88C7;
                selection-color: #FFFFFF;
                font-size: 14px;
            }
        """
    
    def get_about_title_style(self):
        """获取关于页面标题样式"""
        return """
            font-size: 28px; 
            font-weight: bold; 
            color: #4A88C7;
            margin-bottom: 20px;
            padding: 16px;
            background-color: rgba(74, 136, 199, 0.1);
            border-radius: 8px;
            border: 2px solid #4A88C7;
        """
    
    def get_about_version_style(self):
        """获取关于页面版本样式"""
        return """
            font-size: 18px; 
            color: #A9B7C6; 
            margin-bottom: 10px;
            font-weight: bold;
        """
    
    def get_about_author_style(self):
        """获取关于页面作者样式"""
        return """
            font-size: 16px; 
            color: #808080; 
            margin-bottom: 10px;
            font-style: italic;
        """
    
    def get_about_date_style(self):
        """获取关于页面日期样式"""
        return """
            font-size: 14px; 
            color: #808080; 
            margin-bottom: 20px;
        """
    
    def get_about_description_style(self):
        """获取关于页面描述样式"""
        return """
            font-size: 14px; 
            color: #A9B7C6; 
            line-height: 1.6;
            padding: 20px;
            background-color: #3C3F41;
            border-radius: 8px;
            border: 1px solid #555555;
        """
    
    def get_combo_box_style(self):
        """获取下拉框样式"""
        return """
            QComboBox {
                background-color: #3C3F41;
                color: #A9B7C6;
                border: 1px solid #555555;
                border-radius: 4px;
                padding: 6px;
                font-size: 12px;
            }
            QComboBox::drop-down {
                border: none;
            }
            QComboBox::down-arrow {
                image: none;
                border-left: 5px solid transparent;
                border-right: 5px solid transparent;
                border-top: 5px solid #A9B7C6;
            }
        """


# 创建全局样式管理器实例
style_manager = StyleManager()